﻿using Engine;
using Engine.Graphics;
using System.Collections.Generic;

namespace Game
{
    public abstract class AlphaSixFace : Block
    {
        public Texture2D m_OtherTetxure;

        public Texture2D m_texture;

        public string m_texturename;

        public Color m_color;

        public string UnridgetTextureName;

        public AlphaSixFace(string DisplayName, string description, string ClassName, string texturename, Color color, string unridigtTextureName)
        {

            UnridgetTextureName = unridigtTextureName;
            m_texturename = texturename;
            m_color = color;
            base.IsPlacementTransparent = false;
            base.DefaultCategory = "Construction";
            base.Behaviors = "";
            base.DisplayOrder = 78;
            base.DefaultIconBlockOffset = new Vector3(0f, 0f, 0f);
            base.DefaultIconViewOffset = new Vector3(1f, 1f, 1f);
            base.DefaultIconViewScale = 1f;
            base.FirstPersonScale = 0.4f;
            base.FirstPersonOffset = new Vector3(0.5f, -0.5f, -0.6f);
            base.FirstPersonRotation = new Vector3(0f, 40f, 0f);
            base.InHandScale = 0.3f;
            base.InHandOffset = new Vector3(0f, 0.12f, 0f);
            base.InHandRotation = new Vector3(0f, 0f, 45f);
            base.CraftingId = "glass";
            base.DefaultCreativeData = 0;
            base.IsCollidable = true;
            base.IsPlaceable = true;
            base.IsDiggingTransparent = false;
            base.DefaultIsInteractive = false;
            base.IsEditable = false;
            base.IsNonDuplicable = false;
            base.IsGatherable = false;
            base.HasCollisionBehavior = false;
            base.KillsWhenStuck = false;
            base.IsFluidBlocker = true;
            base.IsTransparent = true;
            base.DefaultShadowStrength = 0;
            base.LightAttenuation = 0;
            base.DefaultEmittedLightAmount = 0;
            base.ObjectShadowStrength = 1f;
            base.MaxStacking = 40;
            base.SleepSuitability = 0f;
            base.FrictionFactor = 1f;
            base.Density = 1.5f;
            base.NoAutoJump = false;
            base.NoSmoothRise = false;
            base.FuelHeatLevel = 0f;
            base.FuelFireDuration = 0f;
            base.ShovelPower = 1f;
            base.QuarryPower = 1f;
            base.HackPower = 1f;
            base.DefaultMeleePower = 1f;
            base.DefaultProjectilePower = 2f;
            base.ToolLevel = 1;
            base.Durability = -1;
            base.IsAimable = false;
            base.IsStickable = false;
            base.AlignToVelocity = false;
            base.ProjectileSpeed = 0f;
            base.ProjectileTipOffset = 0f;
            base.DisintegratesOnHit = false;
            base.ProjectileStickProbability = 0f;
            base.FireDuration = 0f;
            base.IsExplosionTransparent = false;
            base.DigMethod = (BlockDigMethod)2;
            base.DefaultTextureSlot = 67;
            base.DestructionDebrisScale = 1f;
        }

        public AlphaSixFace(string DisplayName, string description, string ClassName, string texturename, Color color)
        {

            m_texturename = texturename;
            m_color = color;
            base.IsPlacementTransparent = false;
            base.DefaultCategory = "Construction";
            base.Behaviors = "";
            base.DisplayOrder = 78;
            base.DefaultIconBlockOffset = new Vector3(0f, 0f, 0f);
            base.DefaultIconViewOffset = new Vector3(1f, 1f, 1f);
            base.DefaultIconViewScale = 1f;
            base.FirstPersonScale = 0.4f;
            base.FirstPersonOffset = new Vector3(0.5f, -0.5f, -0.6f);
            base.FirstPersonRotation = new Vector3(0f, 40f, 0f);
            base.InHandScale = 0.3f;
            base.InHandOffset = new Vector3(0f, 0.12f, 0f);
            base.InHandRotation = new Vector3(0f, 0f, 45f);
            base.CraftingId = "glass";
            base.DefaultCreativeData = 0;
            base.IsCollidable = true;
            base.IsPlaceable = true;
            base.IsDiggingTransparent = false;
            base.DefaultIsInteractive = false;
            base.IsEditable = false;
            base.IsNonDuplicable = false;
            base.IsGatherable = false;
            base.HasCollisionBehavior = false;
            base.KillsWhenStuck = false;
            base.IsFluidBlocker = true;
            base.IsTransparent = true;
            base.DefaultShadowStrength = 0;
            base.LightAttenuation = 0;
            base.DefaultEmittedLightAmount = 0;
            base.ObjectShadowStrength = 1f;
            base.MaxStacking = 40;
            base.SleepSuitability = 0f;
            base.FrictionFactor = 1f;
            base.Density = 1.5f;
            base.NoAutoJump = false;
            base.NoSmoothRise = false;
            base.FuelHeatLevel = 0f;
            base.FuelFireDuration = 0f;
            base.ShovelPower = 1f;
            base.QuarryPower = 1f;
            base.HackPower = 1f;
            base.DefaultMeleePower = 1f;
            base.DefaultProjectilePower = 2f;
            base.ToolLevel = 1;
            base.Durability = -1;
            base.IsAimable = false;
            base.IsStickable = false;
            base.AlignToVelocity = false;
            base.ProjectileSpeed = 0f;
            base.ProjectileTipOffset = 0f;
            base.DisintegratesOnHit = false;
            base.ProjectileStickProbability = 0f;
            base.FireDuration = 0f;
            base.IsExplosionTransparent = false;
            base.DigMethod = (BlockDigMethod)2;
            base.DefaultTextureSlot = 67;
            base.DestructionDebrisScale = 1f;
        }

        public override void Initialize()
        {
            m_texture = ContentManager.Get<Texture2D>(m_texturename, (string)null);
            if (!string.IsNullOrEmpty(UnridgetTextureName))
            {
                m_OtherTetxure = ContentManager.Get<Texture2D>(UnridgetTextureName, (string)null);
            }
        }

        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {

            generator.GenerateCubeVertices((Block)(object)this, value, x, y, z, m_color, geometry.GetGeometry(m_texture).OpaqueSubsetsByFace);
        }

        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {

            BlocksManager.DrawCubeBlock(primitivesRenderer, value, new Vector3(size), ref matrix, m_color, m_color, environmentData, m_texture);
        }

        public override int GetTextureSlotCount(int value)
        {
            return 3;
        }

        public override BlockDebrisParticleSystem CreateDebrisParticleSystem(SubsystemTerrain subsystemTerrain, Vector3 position, int value, float strength)
        {

            return new BlockDebrisParticleSystem(subsystemTerrain, position, 1f * strength, base.DestructionDebrisScale, Color.White, base.DefaultTextureSlot);
        }

        public override int GetFaceTextureSlot(int face, int value)
        {
            // 注意：value 参数在这个方法里没有被使用  
            switch (face)
            {
                case 0:
                case 1:
                case 2:
                case 3:
                    return 0; // 对于face为0到3的情况，返回0  
                case 4:
                case 5:
                    return 1; // 对于face为4或5的情况，返回1  
                default:
                    return 0; // 对于其他所有情况，返回0  
            }
        }

        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List<BlockDropValue> dropValues, out bool showDebris)
        {

            if (Random.Bool(0.15f))
            {
                dropValues.Add(new BlockDropValue
                {
                    Value = 304,
                    Count = 1
                });
                showDebris = true;
            }
            if (Random.Bool(0.15f))
            {
                dropValues.Add(new BlockDropValue
                {
                    Value = 23,
                    Count = 1
                });
                showDebris = true;
            }
            else
            {
                showDebris = true;
            }
        }
    }
}
